package com.copd.mapper;

import com.copd.entity.Permission;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface PermissionMapper {
    
    @Select("SELECT * FROM Permissions")
    List<Permission> findAll();
    
    @Select("SELECT * FROM Permissions WHERE permission_id = #{permissionId}")
    Permission findById(Integer permissionId);
    
    @Select("SELECT * FROM Permissions WHERE permission_key = #{permissionKey}")
    Permission findByPermissionKey(String permissionKey);
    
    @Insert("INSERT INTO Permissions(permission_name, permission_key, description) " +
            "VALUES(#{permissionName}, #{permissionKey}, #{description})")
    @Options(useGeneratedKeys = true, keyProperty = "permissionId")
    int insert(Permission permission);
    
    @Update("UPDATE Permissions SET permission_name = #{permissionName}, permission_key = #{permissionKey}, " +
            "description = #{description} WHERE permission_id = #{permissionId}")
    int update(Permission permission);
    
    @Delete("DELETE FROM Permissions WHERE permission_id = #{permissionId}")
    int deleteById(Integer permissionId);
    
    @Select("SELECT p.* FROM Permissions p " +
            "JOIN Role_Permissions rp ON p.permission_id = rp.permission_id " +
            "WHERE rp.role_id = #{roleId}")
    List<Permission> findByRoleId(Integer roleId);
} 